Here we will use some pyhton libraries and analyze the Covid-19 pandemic and its effect in various countries globally
In case of any query you can contact me via gmail: amitabhdeb.nits@gmail.com
#!pip install folium
#!pip install plotly
#imports
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots
import folium
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import math
import random
from datetime import timedelta
import warnings
warnings.filterwarnings('ignore')
#color_pallettes
cnf = '#393e46'
dth = '#ff2e63'
rec = '#21bf73'
act = '#fe9801'
import plotly as py
py.offline.init_notebook_mode(connected=True)
clean_data = pd.read_csv('C:/Users/studd/Downloads/JOB/projects/Covid-19 project/Covid-19-Preprocessed-Dataset-master/Covid-19-Preprocessed-Dataset-master/preprocessed/covid_19_data_cleaned.csv', parse_dates=['Date'])
country_daywise = pd.read_csv('C:/Users/studd/Downloads/JOB/projects/Covid-19 project/Covid-19-Preprocessed-Dataset-master/Covid-19-Preprocessed-Dataset-master/preprocessed/country_daywise.csv', parse_dates=['Date'])
country_wise = pd.read_csv('C:/Users/studd/Downloads/JOB/projects/Covid-19 project/Covid-19-Preprocessed-Dataset-master/Covid-19-Preprocessed-Dataset-master/preprocessed/countrywise.csv')
daywise = pd.read_csv('C:/Users/studd/Downloads/JOB/projects/Covid-19 project/Covid-19-Preprocessed-Dataset-master/Covid-19-Preprocessed-Dataset-master/preprocessed/daywise.csv', parse_dates=['Date'])
clean_data['Province/State'] = clean_data['Province/State'].fillna("")
clean_data.head()
| Date | Province/State | Country | Lat | Long | Confirmed | Recovered | Deaths | Active | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 2020-01-22 | Afghanistan | 33.93911 | 67.709953 | 0 | 0 | 0 | 0 | |
| 1 | 2020-01-23 | Afghanistan | 33.93911 | 67.709953 | 0 | 0 | 0 | 0 | |
| 2 | 2020-01-24 | Afghanistan | 33.93911 | 67.709953 | 0 | 0 | 0 | 0 | |
| 3 | 2020-01-25 | Afghanistan | 33.93911 | 67.709953 | 0 | 0 | 0 | 0 | |
| 4 | 2020-01-26 | Afghanistan | 33.93911 | 67.709953 | 0 | 0 | 0 | 0 |
confirmed = clean_data.groupby('Date').sum()['Confirmed'].reset_index()
recovered = clean_data.groupby('Date').sum()['Recovered'].reset_index()
deaths = clean_data.groupby('Date').sum()['Deaths'].reset_index()
#clean_data.info()
clean_data.query('Country=="India"').tail()
| Date | Province/State | Country | Lat | Long | Confirmed | Recovered | Deaths | Active | |
|---|---|---|---|---|---|---|---|---|---|
| 77547 | 2021-06-24 | India | 20.593684 | 78.96288 | 30134445 | 29128267 | 393310 | 612868 | |
| 77548 | 2021-06-25 | India | 20.593684 | 78.96288 | 30183143 | 29193085 | 394493 | 595565 | |
| 77549 | 2021-06-26 | India | 20.593684 | 78.96288 | 30233183 | 29251029 | 395751 | 586403 | |
| 77550 | 2021-06-27 | India | 20.593684 | 78.96288 | 30279331 | 29309607 | 396730 | 572994 | |
| 77551 | 2021-06-28 | India | 20.593684 | 78.96288 | 30279331 | 29309607 | 396730 | 572994 |
fig = go.Figure()
fig.add_trace(go.Scatter(x = confirmed['Date'], y = confirmed['Confirmed'], mode = 'lines+markers', name = 'Confirmed Cases', line = dict(color = "Red", width = 0.5)))
fig.add_trace(go.Scatter(x = recovered['Date'], y =recovered['Recovered'], mode = 'lines+markers', name = 'Recovered Cases', line = dict(color = "Green", width = 0.5)))
fig.add_trace(go.Scatter(x = deaths['Date'], y = deaths['Deaths'], mode = 'lines+markers', name = 'Deaths Cases', line = dict(color = "Black", width = 0.5)))
fig.update_layout(title = 'WorldWide Covid-19 Cases', yaxis = dict(title = 'Number of Cases'))
fig.show()
clean_data['Date'] = clean_data['Date'].astype(str)
#clean_data.info()
fig = px.density_mapbox(clean_data, lat = 'Lat', lon = 'Long', hover_name = 'Country', hover_data = ['Confirmed', 'Recovered', 'Deaths'], animation_frame= 'Date', color_continuous_scale='Portland', radius=7, zoom=0, height=700)
fig.update_layout(title = 'WorldWide Covid-19 Cases with Time Laps')
fig.update_layout(mapbox_style = 'open-street-map', mapbox_center_lon = 0)
fig.show()
temp = clean_data.groupby('Date')['Recovered','Active', 'Deaths'].sum().reset_index()
temp = temp.melt(id_vars='Date', value_vars=['Deaths', 'Recovered','Active'], var_name='Case', value_name='Count')
fig = px.area(temp, x = 'Date', y = 'Count', color = 'Case', height = 600, title = 'Cases Over Time', color_discrete_sequence=[dth, rec, act])
fig.update_layout(xaxis_rangeslider_visible = True)
fig.show()
top = 15
fig_c = px.bar(country_wise.sort_values('Confirmed').tail(top), x = 'Confirmed', y = 'Country', text = 'Confirmed', orientation = 'h', color_discrete_sequence = [cnf])
fig_a = px.bar(country_wise.sort_values('Active').tail(top), x = 'Active', y = 'Country', text = 'Active', orientation = 'h', color_discrete_sequence = [act])
fig_r = px.bar(country_wise.sort_values('Recovered').tail(top), x = 'Recovered', y = 'Country', text = 'Recovered', orientation = 'h', color_discrete_sequence = [rec])
fig_d = px.bar(country_wise.sort_values('Deaths').tail(top), x = 'Deaths', y = 'Country', text = 'Deaths', orientation = 'h', color_discrete_sequence = [dth])
fig = make_subplots(rows=1, cols=4, shared_xaxes=False, horizontal_spacing=0.14, vertical_spacing=0.1, subplot_titles=('Confirmed Cases', 'Active Cases', 'Recovered Cases', 'Death Cases'))
fig.add_trace(fig_c['data'][0], row = 1, col=1)
fig.add_trace(fig_a['data'][0], row = 1, col=2)
fig.add_trace(fig_r['data'][0], row = 1, col=3)
fig.add_trace(fig_d['data'][0], row = 1, col=4)
fig.update_layout(height = 500)
fig.show()
top = 15
fig = px.scatter(country_wise.sort_values('Deaths', ascending=False).head(top), x = 'Confirmed', y = 'Deaths', color='Country',
size = 'Confirmed', height = 700, text = 'Country', log_x=True, log_y=True, title='Death vs Confirmed cases on Log10 scale')
fig.update_traces(textposition = 'top center')
fig.update_layout(showlegend = True, xaxis_rangeslider_visible = True)
fig.show()
full_latest = clean_data[clean_data['Date'] == max(clean_data['Date'])]
fig = px.treemap(full_latest.sort_values(by = 'Confirmed', ascending=False).reset_index(drop = True), path = ['Country'], values='Confirmed',
height = 700, title='Number of Confirmed Cases', color_discrete_sequence=px.colors.qualitative.Dark2)
fig.data[0].textinfo = 'label+text+value'
fig.show()
full_latest = clean_data[clean_data['Date'] == max(clean_data['Date'])]
fig = px.treemap(full_latest.sort_values(by = 'Deaths', ascending=False).reset_index(drop = True), path = ['Country'], values='Deaths',
height = 700, title='Number of Death Cases', color_discrete_sequence=px.colors.qualitative.Dark2)
fig.data[0].textinfo = 'label+text+value'
fig.show()
The below data is taken from wikipedia
epidemics = pd.DataFrame({
'epidemic' : ['SARS', 'H1N1', 'MERS', 'EBOLA', 'COVID-19'],
'start_year' : [2002, 2009, 2012, 2013, 2019],
'end_year' : [2004, 2010, 2020, 2016, 2021],
'confirmed' : [8422, 6724149, 2519, 28646, full_latest['Confirmed'].sum()],
'deaths' : [813, 19654, 866, 11323, full_latest['Deaths'].sum()]
})
epidemics['mortality'] = round((epidemics['deaths']/epidemics['confirmed'])*100,2)
epidemics.head()
| epidemic | start_year | end_year | confirmed | deaths | mortality | |
|---|---|---|---|---|---|---|
| 0 | SARS | 2002 | 2004 | 8422 | 813 | 9.65 |
| 1 | H1N1 | 2009 | 2010 | 6724149 | 19654 | 0.29 |
| 2 | MERS | 2012 | 2020 | 2519 | 866 | 34.38 |
| 3 | EBOLA | 2013 | 2016 | 28646 | 11323 | 39.53 |
| 4 | COVID-19 | 2019 | 2021 | 181388210 | 3928804 | 2.17 |
temp = epidemics.melt(id_vars='epidemic', value_vars=['confirmed', 'deaths', 'mortality'], var_name= 'Case', value_name='Value')
fig = px.bar(temp, x = 'epidemic', y = 'Value', color='epidemic', text= 'Value', facet_col='Case', color_discrete_sequence=px.colors.qualitative.Bold)
fig.update_traces(textposition='outside')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode = 'hide')
fig.update_yaxes(showticklabels=False)
fig.layout.yaxis2.update(matches=None)
fig.layout.yaxis3.update(matches=None)
fig.show()
With this, we have come to the end of this Data Visualization project on Covid-19. In this project we tried to observe the effect of Covid on various countries all over the world using python and its libraries.